home *** CD-ROM | disk | FTP | other *** search
/ DOpus Plus / DOpus Plus.iso / Tutorial / C Guide / Time_module / ClockConfig.c < prev    next >
C/C++ Source or Header  |  1998-09-20  |  3KB  |  89 lines

  1.  
  2. /* ClockConfig.c
  3. */
  4.  
  5. #include "includes/Clock.h"
  6. #include <libraries/iffparse.h>
  7.  
  8.  
  9. #define ID_PROG        MAKE_ID('D','O','C','C')
  10. #define ID_NUMB        MAKE_ID('N','U','M','M')
  11. #define ID_FONT        MAKE_ID('F','O','N','T')
  12. #define ID_PICT        MAKE_ID('B','G','P','C')
  13.  
  14. BOOL WriteConfig( ClockData *cd )
  15. {
  16.      APTR iffhandle;
  17.           
  18.      if( (iffhandle = IFFOpen(CLOCKCONFIG, IFF_WRITE, ID_PROG)) )
  19.        {  
  20.           IFFPushChunk( iffhandle, ID_NUMB );
  21.           IFFWriteChunkBytes( iffhandle, &cd->ibox,  sizeof(WORD) * 2 );
  22.           IFFWriteChunkBytes( iffhandle, &cd->flags, sizeof(ULONG)    );
  23.           IFFWriteChunkBytes( iffhandle, &cd->txtattr.ta_YSize, sizeof(UWORD) );
  24.           IFFWriteChunkBytes( iffhandle, &cd->txtattr.ta_Style, sizeof(UBYTE) );
  25.           IFFWriteChunkBytes( iffhandle, &cd->itext[0].FrontPen, sizeof(UBYTE) );
  26.           IFFWriteChunkBytes( iffhandle, &cd->itext[0].BackPen, sizeof(UBYTE) );
  27.           IFFWriteChunkBytes( iffhandle, &cd->itext[0].DrawMode, sizeof(UBYTE) );
  28.           IFFWriteChunkBytes( iffhandle, cd->woday, strlen(cd->woday) );
  29.           IFFPopChunk( iffhandle );
  30.                                            
  31.           if( strlen(cd->fontname) > 5 )
  32.             {
  33.               IFFWriteChunk(iffhandle, cd->fontname, ID_FONT, strlen(cd->fontname)+1);
  34.             }
  35.             
  36.           if( cd->picture[0] )
  37.             {
  38.               IFFWriteChunk(iffhandle, cd->picture, ID_PICT, strlen(cd->picture)+1);
  39.             }
  40.           
  41.  
  42.           IFFClose( iffhandle );
  43.           return 0;
  44.         };
  45.                  
  46.      return 1;
  47. }
  48.  
  49.  
  50. BOOL ReadConfig( ClockData *cd )
  51. {
  52.      APTR iffhandle;
  53.      ULONG nextchunk;
  54.           
  55.      if( (iffhandle = IFFOpen(CLOCKCONFIG, IFF_READ, ID_PROG)) )
  56.        {
  57.           while( (nextchunk = IFFNextChunk(iffhandle, 0)) )
  58.             {
  59.                 switch( nextchunk )
  60.                   {
  61.                        case ID_FONT: IFFReadChunkBytes( iffhandle, cd->fontname, 32 );
  62.                                      break;
  63.                                                                  
  64.                        case ID_PICT: IFFReadChunkBytes( iffhandle, cd->picture, 256 );
  65.                                      break; 
  66.                                                                                                          
  67.                        case ID_NUMB: IFFReadChunkBytes(iffhandle, &cd->ibox,  sizeof(WORD) * 2 );
  68.                                      IFFReadChunkBytes(iffhandle, &cd->flags, sizeof(ULONG)    );
  69.                                      IFFReadChunkBytes(iffhandle, &cd->txtattr.ta_YSize, sizeof(UWORD) );
  70.                                      IFFReadChunkBytes(iffhandle, &cd->txtattr.ta_Style, sizeof(UBYTE) );
  71.                                      IFFReadChunkBytes(iffhandle, &cd->itext[0].FrontPen, sizeof(UBYTE) );
  72.                                      IFFReadChunkBytes(iffhandle, &cd->itext[0].BackPen, sizeof(UBYTE) );
  73.                                      IFFReadChunkBytes(iffhandle, &cd->itext[0].DrawMode, sizeof(UBYTE) );
  74.                                      IFFReadChunkBytes(iffhandle, cd->woday, 16 );
  75.                                      break; 
  76.                   };
  77.             };
  78.           IFFClose( iffhandle );
  79.                          
  80.           
  81.           return 0;
  82.          
  83.        };
  84.      return 1;
  85. }
  86.  
  87.  
  88.  
  89.